package v2

import (
	rpcv1 "gluenet/internal/agent/api/rpc/v1"
	corev1 "gluenet/pkg/agent/types"
	"gluenet/pkg/agent/v2/rpc"
)

type PromGetter interface {
	Prom() GluenetPromInterface
}

type GluenetPromInterface interface {
	PromQuery(promQueryReq *corev1.PromQuery) (result []byte, err error)
	PromQueryRange(promQueryRangeReq *corev1.PromQueryRange) (result []byte, err error)
}

type gluenetProm struct {
	client rpc.Interface
}

func newGluenetProm(c *CoreClient) *gluenetProm {
	return &gluenetProm{
		client: c.RPCClient(),
	}
}

func (c *gluenetProm) PromQuery(promQueryReq *corev1.PromQuery) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.PromQuery).
		Spec(*promQueryReq).
		Do().
		Into(&result)
	return
}

func (c *gluenetProm) PromQueryRange(promQueryRangeReq *corev1.PromQueryRange) (result []byte, err error) {
	err = c.client.Invoke().
		Api(rpcv1.PromQueryRange).
		Spec(*promQueryRangeReq).
		Do().
		Into(&result)
	return
}
